<?php if(isset($user_info) && !empty($user_info)){
$ci = & get_instance();
$ci->load->config('wxpay_config');
$ci->load->library('CI_Wechat');
$_rs = $ci->ci_wechat->getJsTicket();
$_appId = $ci->config->config['appid'];
$_baseUrl = $ci->config->config['base_url'];
$_timeStamp = time();
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$_jsUrl = $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$_jsSign = $ci->ci_wechat->getJsSign($_jsUrl,$_timeStamp);
$_nonceStr = $_jsSign['nonceStr'];
$_signature = $_jsSign['signature'];
$_jsApiList = "'checkJsApi','chooseWXPay','onMenuShareTimeline','onMenuShareAppMessage'";

$_platform = $ci->config->item('platform');//平台
$ci->load->library('session');
$_sessid = $ci->session->session_id;

//链接redis
$ci->load->driver('cache');
$ci->cache->redis->is_supported();
$tmp_openid = $ci->cache->redis->getClient()->get("$_platform|WechatCallback|$_sessid");

$session_openid	=	isset($_SESSION['openid'])?$_SESSION['openid']:"";
$_openid = !empty($tmp_openid)?$tmp_openid:$session_openid;
$_shareUrl = $ci->ci_wechat->getOauthRedirect($_baseUrl.'/wechat/shareCallback?openid='.$_openid,'ad230wkdnm2f985jdf93jr');

$ci->load->model('cfd_model');
$yk	= $ci->cfd_model->getHistoryYk($user_info['uid'],'ticket');

$title_arr	=	array(
	"要点啥微盘，快来领免费体验券，还有千元话费天天送！",
	"免费送体验券，天天还有千元话费，快来体验吧！",
	"要点啥微盘，免费体验券送不停，千元话费天天送！",
	"免费送体验券，天天还有千元话费，赢了算你的，亏了算我的！",
	"要点啥微盘疯狂“烧钱”，来晚就没了！"
);

if($yk >=10){
	$content_arr	=	array(
		"我在要点啥靠免费交易体验劵赚了".$yk."元现金，你也一起来免费赚钱吧！",
		"我已经白赚了".$yk."元现金，你还在等什么，你也一起来免费赚钱吧！",
		"我在要点啥靠免费交易体验劵赚了".$yk."元现金，赶紧来一起赚钱吧！"
	);
}else{
	$content_arr	=	array(
		"我正在要点啥微盘免费交易，送您一张体验券，一起来试试吧",
		"亲，要点啥微盘免费玩，千元话费天天送，还犹豫什么，赶紧来吧",
		"赠送您一张要点啥微盘体验券，赢了算你的，亏了算我的，还不赶紧来"
	);
}

$title_keys		= rand(0, 4);
$share_title	= $title_arr[$title_keys];
$content_keys	= rand(0, 2);
$share_content	= $content_arr[$content_keys];

?>
<?php }?>

<script src="//res.wx.qq.com/open/js/jweixin-1.1.0.js" type="text/javascript"></script>
<script type="text/javascript">
wx.config({
	// debug: true,
    appId: '<?php echo $_appId;?>', // 必填，公众号的唯一标识
    timestamp: <?php echo $_timeStamp;?>, // 必填，生成签名的时间戳
    nonceStr: '<?php echo $_nonceStr;?>', // 必填，生成签名的随机串
    signature: '<?php echo $_signature;?>',// 必填，签名，见附录1
    jsApiList: [<?php echo $_jsApiList;?>] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
});

var share_title		=	"<?php echo $share_title;?>";
var share_content	=	"<?php echo $share_content;?>";

wx.ready(function () {
	wx.onMenuShareTimeline({
		'title': share_title, // 分享标题
		'link': '<?php echo $_shareUrl;?>', // 分享链接
		'imgUrl': '<?php echo img_url("/wcp/logo2.jpg"); ?>', // 分享图标
		success: function () { 
			$.get("/cny/callback?action=onMenuShareTimeline&status=success");
		},
		cancel: function () { 
			$.get("/cny/callback?action=onMenuShareTimeline&status=cancel");
		}
	});


	wx.onMenuShareAppMessage({
		'title': share_title, // 分享标题
		'desc': share_content,
		'link': '<?php echo $_shareUrl;?>', // 分享链接
		'imgUrl': '<?php echo img_url("/wcp/logo2.jpg"); ?>', // 分享图标
		success: function () { 
			$.get("/cny/callback?action=onMenuShareAppMessage&status=success");
		},
		cancel: function () { 
			$.get("/cny/callback?action=onMenuShareAppMessage&status=cancel");
		}
	});
});

</script>
